import { RouteRecordRaw, createRouter, createWebHashHistory } from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
// const routes : Array<RouteRecordRaw>=[{
//     path:"/",
//     name: 'home',
//     component: () => import('@/views/home/index.vue'),
//     meta: {
//     },
//     children:[]
// }];

//  公共路由

// eager：true,默认懒加载
const modules: Record<string, any> = import.meta.glob('./modules/*.ts', {
    eager: true,
});
const routes: Array<RouteRecordRaw> = [];

Object.keys(modules).forEach((key) => {
    const module = modules[key].default;
    routes.push(module);
});

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});
// const noAuthRoutes = ['/login', '/home', '/search'];
router.beforeEach(async (_to, _from, next) => {
    NProgress.start();
    // const token = sessionStorage.getItem('userInfo');
    // const userIsLogin = token ? true : false;
    // if (userIsLogin || noAuthRoutes.includes(_to.path)) {
    //     handleUpdateBreadcrumb(_to.name as string);
    //     next();
    // } else {
    //     next('/login');
    // }
    next();
});

router.afterEach(() => {
    NProgress.done();
});

export default router;
